package com.ruoyi.consumer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.consumer.domain.CFillingStation;
import com.ruoyi.consumer.service.ICFillingStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 加注站Controller
 *
 * @author shunxin
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/consumer/station")
public class CFillingStationController extends BaseController
{
    @Autowired
    private ICFillingStationService cFillingStationService;

    /**
     * 查询加注站列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(CFillingStation cFillingStation)
    {
        startPage();
        List<CFillingStation> list = cFillingStationService.selectCFillingStationList(cFillingStation);
        return getDataTable(list);
    }

    /**
     * 导出加注站列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:station:export')")
    @Log(title = "加注站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CFillingStation cFillingStation)
    {
        List<CFillingStation> list = cFillingStationService.selectCFillingStationList(cFillingStation);
        ExcelUtil<CFillingStation> util = new ExcelUtil<CFillingStation>(CFillingStation.class);
        util.exportExcel(response, list, "加注站数据");
    }

    /**
     * 获取加注站详细信息
     */
    @PreAuthorize("@ss.hasPermi('consumer:station:query')")
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") Integer stationId)
    {
        return success(cFillingStationService.selectCFillingStationByStationId(stationId));
    }

    /**
     * 新增加注站
     */
    @PreAuthorize("@ss.hasPermi('consumer:station:add')")
    @Log(title = "加注站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CFillingStation cFillingStation)
    {
        return toAjax(cFillingStationService.insertCFillingStation(cFillingStation));
    }

    /**
     * 修改加注站
     */
    @PreAuthorize("@ss.hasPermi('consumer:station:edit')")
    @Log(title = "加注站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CFillingStation cFillingStation)
    {
        return toAjax(cFillingStationService.updateCFillingStation(cFillingStation));
    }

    /**
     * 删除加注站
     */
    @PreAuthorize("@ss.hasPermi('consumer:station:remove')")
    @Log(title = "加注站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stationIds}")
    public AjaxResult remove(@PathVariable Integer[] stationIds)
    {
        return toAjax(cFillingStationService.deleteCFillingStationByStationIds(stationIds));
    }
}
